package homework;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;

/**
 * @classname:demo05_2
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/10 11:48
 * @version: 0.1
 * @since:1.8
 */
public class demo05_2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入第一个时间");
        String time1 = input.nextLine();
        System.out.println("请输入第二个时间");
        String time2 = input.nextLine();
        String PATTERN = "yyyy-MM-dd HH:mm:ss";
        DateTimeFormatter formatter =DateTimeFormatter.ofPattern(PATTERN);
        LocalDateTime parse = LocalDateTime.parse(time1,formatter);
        LocalDateTime parse1 = LocalDateTime.parse(time2,formatter);
        long until = parse.until(parse1, ChronoUnit.HOURS);
        System.out.println("两个时间相差"+Math.abs(until)+"小时");
    }
}
